@extends('admin.common.app')
@section('cont')
    <section class="Hui-article-box">
        <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
            <span class="c-gray en">&gt;</span>管理员中心
            <span class="c-gray en">&gt;</span>修改角色
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
               href="javascript:location.replace(location.href);" title="刷新">
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
        </nav>
        <article class="cl pd-20">
            <form action="{{ route('admin.role.update',$data) }}" method="post" class="form form-horizontal"
                  id="form-admin-add">
                @method('PUT')
                @csrf
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名：</label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <input type="text" class="input-text" placeholder="请输入角色名" value="{{$data->name}}" name="name"
                               autocomplete="off">
                    </div>
                </div>
                <div class="row cl">
                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                        <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;修改角色&nbsp;&nbsp;">
                    </div>
                </div>
            </form>
        </article>
    </section>
@endsection
@section('js')
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#form-admin-add").validate({
                rules: {
                    name: {
                        required: true,
                    },
                },
                message: {
                    name: {
                        required: '角色名不能为空',
                    },
                },
                onkeyup: false,
                success: "valid",
                submitHandler: function (form) {
                    let url = $(form).attr('action');
                    //表单序列化
                    let data = $(form).serialize();
                    $.ajax({
                       url,
                       data,
                       type:"PUT",
                    }).then(({status, msg}) => {
                        if (status == 0) {
                            layer.msg(msg, {icon: 1, time: 3000}, () => {
                                window.location.href = '{{route('admin.role.index')}}';
                            })
                        } else {
                            layer.msg(msg, {icon: 2, time: 3000})
                        }
                    });
                }
            });
        });
    </script>

@endsection
